package com.example.demo.producer;


import com.example.utils.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author xiao
 * @Date 2025/5/6 下午 2:38
 * @ClassName: MyExceptionHandler
 * @Desc:
 */
@RestControllerAdvice
@Slf4j
public class MyExceptionHandler{




    @ExceptionHandler(Exception.class)
    public ResponseEntity<Map<String, Object>> handleException(Exception e){
        log.info("用户id为;{}" , UserContext.getUserId());
        log.error("发送了异常,异常信息:{}", e.getMessage());
        HashMap<String, Object> response = new HashMap<>();
        response.put("message", "服务器内部错误");
        return ResponseEntity.status(500).body(response);
    }
}
